home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
202_01
/
ked2.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
25KB
|
712 lines
#include <stdio.h>
#include <ctype.h>
#include <ked.h>
getchr() /* low-level character input */
{
char c;
c = getch();
putch(c);
return c;
}
int lower(c)
char c;
{
return isupper(c) ? c+32 : c;
}
int upper(c)
char c;
{
return islower(c) ? c-32 : c;
}
readin(w) /* find location of command in comm array or symbol table */
char w[];
{
int c,i,l,m;
do {
inputs(w);
if ((m = match(w,comm,MAXCOMM)) != NOMATCH)
return m;
if (m == NOMATCH && last != first && p != pr) {
l = pr->lastin;
if (l == 15)
l = last;
for (i = first; i != l; i = new[i].nextin)
if ((c = strcomp(w,new[i].defname)) == 0)
return ( -i - 1);
}
printf("INVALID COMMAND. TYPE MN TO SEE MENU.\n?");
} while (m == NOMATCH);
}
menu() /* print updated menu */
{
int i;
printf("THE FOLLOWING IS A LIST OF VALID ");
printf("COMMANDS FOR THIS EDITOR.\n\n");
printf(" INSTRUCTIONS\n");
printf("m move\n");
printf("tl turnleft\n");
printf("pi pickbeeper\n");
printf("pu putbeeper\n");
printf("to turnoff\n");
printf("b BEGIN\n");
printf("bx BEGINNING-OF-EXECUTION\n");
printf("nd END\n");
printf("ndc end construct\n");
printf("ndx END-OF-EXECUTION\n");
printf("if IF\n");
printf("el ELSE\n");
printf("it ITERATE\n");
printf("wh WHILE\n");
printf("df DEFINE-NEW-INSTRUCTION\n");
printf("\nTYPE ANY KEY TO CONTINUE.\n");
getchr();
if (last != first) { /* any valid sym tab entries? */
printf("\n USER-DEFINED COMMANDS\n");
for (i = first; i != last; i = new[i].nextin)
printf("%s\n", new[i].defname);
}
printf("\n EDIT COMMANDS\n");
printf("n move pointer to next instruction\n");
printf("nc move pointer to next construct\n");
printf("n- move pointer to previous instruction\n");
printf("n-- move pointer back 10 lines\n");
printf("d delete current instruction\n");
printf("c print current line\n");
printf("p print next 20 lines\n");
printf("i insert new instruction before current one\n");
printf("t move pointer to the first line\n");
printf("l list the rest of the program\n");
printf("s save the program\n");
printf("mn print an updated menu\n");
printf("q quit the edit program\n");
printf("\nTYPE ANY KEY TO CONTINUE.\n");
getchr();
printf("\n TESTS\n");
printf("n facing-north\n");
printf("nn not-facing-north\n");
printf("s facing-south\n");
printf("ns not-facing-south\n");
printf("e facing-east\n");
printf("ne not-facing-east\n");
printf("w facing-west\n");
printf("nw not-facing-west\n");
printf("c next-to-a-beeper (beeper on corner)\n");
printf("nc not-next-to-a-beeper\n");
printf("b any-beepers-in-beeper-bag\n");
printf("nb no-beepers-in-beeper bag\n");
printf("f front-is-clear\n");
printf("nf front-is-blocked\n");
printf("l left-is-clear\n");
printf("nl left-is-blocked\n");
printf("r right-is-clear\n");
printf("nr right-is-blocked\n");
}
createtree() /* reads information from old file1 */
{
int i,in,d,fn,fs,b,t,l;
char *malloc();
fscanf(fptr1, "%d %d %d %d %d %d %d %d",
&i,&in,&d,&fn,&fs,&b,&t,&l);
pr = NULL;
p = (struct tnode *)malloc(24);
tree(i,in,d,fn,fs,b,t,l); /* store first node */
root = p;
p = root->sub = (struct tnode *)malloc(24);
pr = root;
fscanf(fptr1, "%d %d %d %d %d %d %d %d",
&i,&in,&d,&fn,&fs,&b,&t,&l);
while (i != NDX && i != CPMEOF && i != EOF) {
createnode(fptr1,i,in,d,fn,fs,b,t,l);
fscanf(fptr1, "%d %d %d %d %d %d %d %d",
&i,&in,&d,&fn,&fs,&b,&t,&l);
}
endcons();
tree(i,in,d,fn,fs,b,t,l);
pr = p;
fclose(fptr1);
}
createnode(fptr1,i,in,d,fn,fs,b,t,l) /* restores nodes for parse tree */
FILE *fptr1;
int i,in,d,fn,fs,b,t,l;
{
int j;
char w[MAXLINE];
struct tnode *allocp();
if (d == NEWINSTR && pr->instr != DEF) {
i = reloc[i]; /* set up array to convert */
j = 0; /* old symb tab to new */
while (new[i].loc[j] != NULL)
j++;
new[i].loc[j] = p;
new [i].loc[++j] = NULL;
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->next = allocp();
} else switch (i) {
case 0: /* move */
case 1: /* turnleft */
case 2: /* pickbeeper */
case 3: /* putbeeper */
case 4: /* turnoff */
while (in < pr->indent)
endcons();
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->next = allocp();
break;
case 5: /* BEGIN */
case 7: /* BEGINNING-OF-EXECUTION */
case 13: /* ELSE */
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->sub = allocp();
break;
case 8: /* END */
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->next = allocp();
endcons();
break;
case 11: /* IF */
while (in < pr->indent)
endcons();
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->sub = allocp();
fscanf(fptr1,"%d %d %d %d %d %d %d %d",
&i,&in,&d,&fn,&fs,&b,&t,&l); /* get test */
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->sub = allocp();
fscanf(fptr1, "%d %d %d %d %d %d %d %d",
&i,&in,&d,&fn,&fs,&b,&t,&l); /* get THEN */
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->sub = allocp();
break;
case 14: /* ITERATE */
case 15: /* WHILE */
while (in < pr->indent)
endcons();
if (l != 15)
l = last;
tree(i,in,d,fn,fs,b,t,l);
p = p->sub = allocp();
fscanf(fptr1,